package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.api.db.OptionApi;
import com.tanhua.dubbo.api.mapper.OptionMapper;
import com.tanhua.model.db.Option;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author lamy
 * @version 1.0
 * @ClassName: OptionApiImpl
 * @date 2021-12-26 21:43:52
 */
//选项API实现类
@DubboService
public class OptionApiImpl implements OptionApi {
    @Autowired
    private OptionMapper optionMapper;

    //根据问题的id来查询对应的选项
    @Override
    public List<Option> findAll(Long id) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("problem_id",id);
        return optionMapper.selectList(queryWrapper);
    }

    //根据optionId返回一个optional对象
    @Override
    public Option getOption(Long optionId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",optionId);
        return optionMapper.selectOne(queryWrapper);
    }


}
